package com.zb.sannuo.thereport.controller;

import com.zb.sannuo.common.domain.search.Abnormal;
import com.zb.sannuo.common.domain.vo.ReportVo;
import com.zb.sannuo.common.result.Result;
import com.zb.sannuo.common.result.ResultCode;
import com.zb.sannuo.thereport.service.AbnormalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.lang.Integer.parseInt;

@RestController
@RequestMapping("/reports")
@Api(value = "报表管理模块",description = "指标异常率报表")
@CrossOrigin
public class AbnormalController {


    @Resource
    private AbnormalService abnormalServiceImpl;

    @ApiOperation(value = "查询指标异常率",notes = "查询指标异常率",httpMethod = "GET")
    @RequestMapping(value = "abnormal",method = RequestMethod.GET)
    public Result queryAbnormal(String searchParams) throws Exception{
//        方法一:数组遍历
//        List<Abnormal> list = abnormalServiceImpl.queryAbnormal(reportVo);
//        Integer[] arr = new Integer[12];
//        Integer[] arr1 = new Integer[12];
//        Integer[] arr2 = new Integer[12];
//        for (int j = 1; j <= 12; j++) {
//            boolean bo = true;
//            boolean bo1 = true;
//            Abnormal abnormal = null;
//            for (Abnormal abnormal1 : list) {
//                if (parseInt(abnormal1.getMonth())==j){
//                    if (abnormal1.getSex()==0){
//                        arr[j-1] = abnormal1.getToTa();
//                        bo = false;
//                    }else if (abnormal1.getSex()==1){
//                        arr1[j-1] = abnormal1.getToTa();
//                        bo1 = false;
//                    }
//                }
//            }
//            if(bo){
//                arr[j-1] = 0;
//            }
//            if(bo1){
//                arr1[j-1] = 0;
//            }
//        }
//        for (int i = 0; i < arr.length; i++) {
//            arr2[i] = arr[i] + arr1[i];
//            System.out.println("女:"+arr[i] + ",男:" + arr1[i] + ",合计:" + arr2[i]);
//        }
//
//        Map<String,Integer[]> map = new HashMap<>();
//        map.put("arr",arr);
//        map.put("arr1",arr1);
//        map.put("arr2",arr2);
//        return Result.ok(ResultCode.SUCCESS,map);

        // 方法二:

        List<Abnormal> list = abnormalServiceImpl.queryAbnormal(searchParams);
        System.out.println(searchParams);
        return Result.ok(ResultCode.SUCCESS,list);

    }
}
